{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
      <div class="layui-inline">
      <label class="layui-form-label">类型</label>
        <div class="layui-input-inline">
          <select class="layui-input" name='type' id='type'>
            <option value="">全部</option>
            {foreach $type as $vo}
              <option value="{$vo.type}">{$vo.remark}</option>
            {/foreach}
          </select>
        </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">钱包</label>
          <div class="layui-input-inline">
              <select class="layui-input" name='wid' id='wid'>
                <option value="">全部</option>
                {foreach $wallet as $vo}
                  <option value="{$vo.id}">{$vo.name}</option>
                {/foreach}
              </select>
          </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">用户ID</label>
          <div class="layui-input-inline">
            <input type="text" name="uid" autocomplete="off" class="layui-input" id='uid'>
          </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-inline">
              <input type="text" name="username" autocomplete="off" class="layui-input" id='username'>
          </div>
      </div>
      <!-- <div class="layui-inline">
          <label class="layui-form-label">备注</label>
          <div class="layui-input-inline">
              <input type="text" name="remark" autocomplete="off" class="layui-input" id='remark'>
          </div>
      </div> -->
      
            <div class="layui-inline">
          <label class="layui-form-label">时间</label>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="start_time" id="start_time" placeholder="yyyy-MM-dd">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="end_time" id="end_time" placeholder="yyyy-MM-dd">
          </div>
      </div>
      <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn" data-type="reload">搜索</button>
          <!-- <button class="layui-btn" onclick="excel()">导出表</button> -->
        </div>
      </div>
  <table id="table" lay-filter="table"></table>
</div>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/balance/dataList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      {field:'uid', title: '用户ID', width: 100 }
      ,{field:'username', title: '用户名', width: 150 }
      ,{field:'phone', title: '电话', width: 150}
      ,{field:'wallet_name', title: '钱包', width: 150}
      ,{field:'before_balance', title: '变动前', width: 150}
      ,{field:'balance', title: '变动金额', width: 200,templet: function(d){
          if (d.balance>0) {
          return '<span style="color:red">'+d.balance+'</span>'
          } else {
            return '<span style="color:green">'+d.balance+'</span>'
          }
      }}
      ,{field:'after_balance', title: '变动后', width: 200}
      ,{field:'remark', title: '备注', width: 300}
      ,{field:'order_remark', title: '其他备注', width: 300}
      ,{field:'change_date', title: '时间', width: 300}
    ]]
  }); 
        //日期
  laydate.render({
    elem: '#start_time'
  });
  laydate.render({
    elem: '#end_time'
  });
  // 搜索
  var $ = layui.$, active = {
        reload: function(){
            table.reload('reload', {
                where: {
                    type: $('#type').val(),
                    uid: $('#uid').val(),
                    wid: $('#wid').val(),
                    wallet_name: $('#wallet_name').val(),
                    username: $('#username').val(),
                    remark: $('#remark').val(),
                    phone: $('#phone').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
            });
        }
    };
    $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
function excel(){
  var post_data = {
                    type: $('#type').val(),
                    uid: $('#uid').val(),
                    wallet_name: $('#wallet_name').val(),
                    username: $('#username').val(),
                    remark: $('#remark').val(),
                    phone: $('#phone').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
  $.ajax({
    url:"/admin/balance/Excel",
    type:"POST",
    data:post_data,
    success:function(ret){
      //alert(ret);
      location.href='/'+ret;
    }
}); 
}
</script>
{/block}
